//
// Created by Administrator on 2024/10/28.
//

#ifndef AI_PACS_COROUTINE_H
#define AI_PACS_COROUTINE_H

#include <coroutine>
#include <iostream>

template<typename PromiseType>
struct Awaiter {
    PromiseType *p_;

    bool await_ready() { return false; }

    bool await_suspend(std::coroutine_handle<PromiseType> h) {
        p_ = &h.promise();
        return false;
    }

    PromiseType *await_resume() { return p_; }
};

template <typename T>
struct Promise {
    struct promise_type {
        T value_;

        Promise get_return_object() {
            return Promise{.h_ = std::coroutine_handle<promise_type>::from_promise(*this)};
        }

        std::suspend_never initial_suspend() { return {}; }
        std::suspend_never final_suspend() noexcept { return {}; }
        void unhandled_exception() {}
    };

    std::coroutine_handle<promise_type> h_;
    operator std::coroutine_handle<promise_type>() const {
        return h_;
    }
};



#endif //AI_PACS_COROUTINE_H
